package com.guang.springbootrequestversion.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
public class ParamController {

    @GetMapping(path = "paramone")
    public String paramOne(Map<String,Object> map,
                           Model model,
                           HttpServletRequest httpServletRequest,
                           HttpServletResponse httpServletResponse11){
        map.put("one","one");
        model.addAttribute("two","two");
        httpServletRequest.setAttribute("three","three");
        return "forward:/paramtwo";
    }

    @ResponseBody
    @GetMapping(path = "paramtwo")
    public List<Object> paramTwo(HttpServletRequest httpServletRequest){
        Object one = httpServletRequest.getAttribute("one");
        Object two = httpServletRequest.getAttribute("two");
        Object three = httpServletRequest.getAttribute("three");
        List<Object> objects = Arrays.asList(one, two, three);
        return objects;
    }

}
